// operation-user-model.js - A mongoose model
// 
// See http://mongoosejs.com/docs/models.html
// for more of what you can do here.
/**
 * operation-user save data for processing operation, usages for the model:
 * 1) once process reach 100, then means process operation is done, progress is 0, means start
 * 2) processing operation will list in user's operation list, meanwhile, ready operation will
 * also list for user to process
 * 3) if other operation send message, alert or other data to user, will create a process operation
 * for user, once processing-operation is done(100%), write to operation history and the remove 
 * processing operation from processing operation list
 * @param {*} app 
 */
module.exports = function (app) {
  const mongooseClient = app.get('mongooseClient');
  const { Schema } = mongooseClient;
  const { progressSchema } = require('./common-schemas');
  
  const operationUser = new Schema({
    operation: { 
      oid: { type: Schema.Types.ObjectId },
      data: { type: Schema.Types.Mixed }
    },
    user: {
      oid: { type: Schema.Types.ObjectId },
      data: { type: Schema.Types.Mixed }
    },
    progress: { type: progressSchema }, //percentage value
    data: { type: Schema.Types.Mixed },
  }, {
    timestamps: true
  });

  return mongooseClient.model('operationUser', operationUser);
};
